home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / WIN_PRO / DS-1.ZIP;1 / RUNTIME.ZIP / ISTART.R < prev    next >
Encoding:
Text File  |  1992-02-10  |  2.6 KB  |  106 lines

  1. #if !COMPILER
  2. /*
  3.  *  Main program if Icon is called as a subprogram.
  4.  */
  5.  
  6. #ifdef IconCalling
  7.  
  8. novalue main(argc,argv)
  9.  
  10. int argc;
  11. char *argv[];
  12.    {
  13.    int clargc;
  14.    char **clargv;
  15.    int i;
  16.    struct descrip darg;
  17.  
  18. #if AMIGA
  19. #if AZTEC_C
  20.    struct Process *FindTask();
  21.    struct Process *Process = FindTask(0L);
  22.    ULONG stacksize = *((ULONG *)Process->pr_ReturnAddr);
  23.  
  24.    if (stacksize < ICONXMINSTACK) {
  25.       fprintf(stderr,"Iconx needs \"stack %d\" to run\n",ICONXMINSTACK);
  26.       exit(-1);
  27.       }
  28. #endif                    /* AZTEC_C */
  29. #endif                    /* AMIGA */
  30.  
  31.    /*
  32.     * Set up standard Icon interface.  This is only necessary so that
  33.     *  Icon can behave normally as if it were the main program.
  34.     *  It is not necessary if Icon is called by a C program for another
  35.     *  purpose.
  36.     */
  37.  
  38. #if VMS
  39.    redirect(&argc, argv, 0);
  40. #endif                    /* VMS */
  41.  
  42. #ifdef CRAY
  43.    argv[0] = "iconx";
  44. #endif                    /* CRAY */
  45.  
  46. #if SASC
  47.    quite(1);            /* suppress C library diagnostics */
  48. #endif                    /* SASC */
  49.  
  50.    icon_setup(argc, argv, &i);
  51.    while (i--) {            /* skip option arguments */
  52.       argc--;
  53.       argv++;
  54.       }
  55.  
  56.    if (!argc) 
  57.       error("no icode file specified");
  58.  
  59.    /*
  60.     * Read in the icode file argv[1] and initialize the Icon system.
  61.     *  This must be done for any C program calling Icon.
  62.     */
  63.    icon_init(argv[1]);
  64.  
  65.    /*
  66.     * Skip the names of the executable and the file it processes.  This
  67.     *  is necessary only to get the right arguments from the command line
  68.     *  to call Icon as if it were the main program and hence provide
  69.     *  the correct values in the list that is the argument of Icon's main
  70.     *  procedure. This is not necessary if Icon is called from C for
  71.     *  another purpose.
  72.     */
  73.    clargv = argv + 2;
  74.    clargc = argc - 2;
  75.  
  76.    /*
  77.     * Set up a temporary stack and build the necessary list
  78.     *  to call main.
  79.     */
  80.    sp = stack + Wsizeof(struct b_coexpr);
  81.  
  82.    PushNull;
  83.    argp = (dptr)(sp - 1);
  84.    for (i = 0; i < clargc; i++) {
  85.       PushAVal(strlen(clargv[i]));
  86.       PushVal(clargv[i]);
  87.       }
  88.    Ollist(clargc, argp);
  89.  
  90.    /*
  91.     * Now that the list is computed, copy its descriptor off the
  92.     *  stack (which is about to be destroyed), reset the argument
  93.     *  pointer, and make the call to the Icon main procedure.
  94.     */
  95.  
  96.    darg = *argp;
  97.    argp = 0;
  98.    icon_call("main", 1, &darg);    /* return signal and value ignored */
  99.    c_exit(NormalExit);
  100.  
  101.    }
  102. #else                    /* IconCalling */
  103. static char x;                /* avoid empty module */
  104. #endif                    /* IconCalling */
  105. #endif                    /* !COMPILER */
  106.